package com.su.gulimall.search.thread;

import java.util.concurrent.*;

public class Handle {
    public static ThreadPoolExecutor executor = new ThreadPoolExecutor(
            5,200,10,
            TimeUnit.SECONDS,new LinkedBlockingDeque<>(100000),
            Executors.defaultThreadFactory(),new ThreadPoolExecutor.AbortPolicy());

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        CompletableFuture<Integer> future = CompletableFuture.supplyAsync(() -> {
            System.out.println("当前线程:" + Thread.currentThread().getId());
            int i = 10 / 0;
            System.out.println("运行结果为：" + i);
            return i;
        }, executor).handle((res,exception)->{
            if(res!=null)
            {
                return res*2;
            }
            if(exception!=null)
            {
                return 0;
            }
          return 0;
        });
        Integer integer=future.get();
        System.out.println("main----------end"+integer);
    }

}
